
set(CMSIS_DIR ${CMAKE_SOURCE_DIR}/thirdparty/cmsis)

get_filename_component(CURRENT_DIR_NAME ${CMAKE_CURRENT_SOURCE_DIR} NAME)
set(driver_name driv_${CURRENT_DIR_NAME})

#stm32f4xx_hal
set(STM32_HAL_DIR ${CMAKE_SOURCE_DIR}/thirdparty/stm32f4_hal)
set(STM32_HAL_SRCS
    ${STM32_HAL_DIR}/src/misc.c
    ${STM32_HAL_DIR}/src/stm32f4xx_adc.c
    ${STM32_HAL_DIR}/src/stm32f4xx_can.c
    ${STM32_HAL_DIR}/src/stm32f4xx_cec.c
    ${STM32_HAL_DIR}/src/stm32f4xx_dma.c
    ${STM32_HAL_DIR}/src/stm32f4xx_exti.c
    ${STM32_HAL_DIR}/src/stm32f4xx_flash.c
    ${STM32_HAL_DIR}/src/stm32f4xx_fsmc.c
    ${STM32_HAL_DIR}/src/stm32f4xx_gpio.c
    ${STM32_HAL_DIR}/src/stm32f4xx_i2c.c
    ${STM32_HAL_DIR}/src/stm32f4xx_iwdg.c
    ${STM32_HAL_DIR}/src/stm32f4xx_pwr.c
    ${STM32_HAL_DIR}/src/stm32f4xx_qspi.c
    ${STM32_HAL_DIR}/src/stm32f4xx_rcc.c
    ${STM32_HAL_DIR}/src/stm32f4xx_rng.c
    ${STM32_HAL_DIR}/src/stm32f4xx_rtc.c
    ${STM32_HAL_DIR}/src/stm32f4xx_sdio.c
    ${STM32_HAL_DIR}/src/stm32f4xx_spi.c
    ${STM32_HAL_DIR}/src/stm32f4xx_syscfg.c
    ${STM32_HAL_DIR}/src/stm32f4xx_tim.c
    ${STM32_HAL_DIR}/src/stm32f4xx_usart.c
    ${STM32_HAL_DIR}/src/stm32f4xx_wwdg.c
    ${STM32_HAL_DIR}/src/system_stm32f4xx.c
)

file(GLOB_RECURSE  BOARD_DRIV_SRCS src/*.c src/*_gcc.s)

add_library(${driver_name} STATIC
    ${STM32_HAL_SRCS}
    ${BOARD_DRIV_SRCS}
)
target_include_directories(${driver_name}
    PRIVATE
        ${STM32_HAL_DIR}/inc
        ${CMSIS_DIR}
        src
    PUBLIC
        ..
)

string(TOUPPER ${CURRENT_DIR_NAME} BOARD_NAME_UPPER)

target_compile_definitions(${driver_name}
    PRIVATE
        USE_STDPERIPH_DRIVER
        STM32F40_41xxx
        $<$<CONFIG:Debug>:USE_FULL_ASSERT>
    PUBLIC
        EV_BOARD_${BOARD_NAME_UPPER}=1
)

target_compile_options(${driver_name} PRIVATE
    -Wno-unused-parameter
)
